In [2]:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.keys import Keys
import time

Starting the browser, search Konkurse


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [3]:
driver = webdriver.Firefox()
search_url = "https://www.shab.ch/shabforms/COMMON/search/searchForm.jsf?category=KK"
driver.get(search_url)

In [6]:
empty_field = driver.find_element_by_id('KEYWORDS')
empty_field.send_keys('Restaurant')

In [9]:
driver.find_element_by_id('TIMESPAN_TOTAL').click()

In [ ]:


In [ ]:


In [13]:
#Searching for Search input
driver.find_element_by_id('KEYWORDS').send_keys('Restaurant')

In [14]:
# Searching for total period of time
driver.find_element_by_id('TIMESPAN_TOTAL').click()

In [ ]:


In [ ]:


In [12]:
driver.find_element_by_class_name('btn').click()

In [18]:
# For some reaon the search button doesn't work
button = driver.find_element_by_class_name('btn')
button.click()

In [ ]:


In [ ]:


In [ ]:


In [ ]:
#so working with Enter
driver.find_element_by_id('ORGANISATION_TX').send_keys(Keys.ENTER)

 Now I want to get all the texts, and save them off


In [13]:
#making folder
!mkdir files2

In [15]:
text = driver.page_source

In [31]:
#And now I need to saved off a file into the folder

file = open('files2/file.htm',"r") 
file.write(text)
file.close()

In [53]:
#lets find the last page
string = driver.find_element_by_class_name('flRight').text
final_number = int(string.split("|")[0].split('von')[1].strip())

In [52]:
#lets find the correct forward button
driver.find_element_by_link_text('»').click()

 Lets put it all together


In [19]:
text = driver.find_element_by_class_name('flRight').text

In [28]:
round(int(text.split('|')[0].split('von')[1].strip()) /10)


Out[28]:
43

In [29]:
driver = webdriver.Firefox()
search_url = "https://www.shab.ch/shabforms/COMMON/search/searchForm.jsf?category=KK"
driver.get(search_url)

driver.find_element_by_xpath("//*[contains(text(), 'Deutsch')]").click()

#Searching for Search input
driver.find_element_by_id('KEYWORDS').send_keys('Restaurant')

#Searching for total period of time
driver.find_element_by_id('TIMESPAN_TOTAL').click()

#Start
driver.find_element_by_id('ORGANISATION_TX').send_keys(Keys.ENTER)

#We need to wait for page to load
time.sleep(5)

#Final number
string = driver.find_element_by_class_name('flRight').text
final_number = int(string.split("|")[0].split('von')[1].strip())
final_number = int(final_number / 10) + 1
final_number

for page in range(1,final_number):
    
    text = driver.page_source
    file = open('files/' + str(page) + '.htm',"w") 
    file.write(text)
    file.close()
    
    driver.find_element_by_link_text('»').click()
    
driver.quit()

In [14]:


In [ ]:


In [ ]: